#include <gtk/gtk.h>

//XPM
static char * gtk_xpm[] = {
"32 39 5 1",
".           c none",
"+          c black",
"@         c #3070E0",
"#          c #F05050",
"$          c #35E035",
" . . . . . . . . . . . . . . + + + + + . . . . . . . . . . . . . " ,
" . . . . . . . . . . . . + + + + + @ @ + + . . . . . . . . . . . " ,
" . . . . . . . . . . + + + + + @ @ @ @ @ @ + + . . . . . . . . . " ,
" . . . . . . . . + + + + @ @ @ @ @ @ @ @ @ @ + + . . . . . . . . " ,
" . . . . . . + + + + @ @ + + + + + + + + @ @ @ + + . . . . . . . " ,
" . . . . . + + + @ @ @ + + + + + + + + + + + @ @ @ + + . . . . . " ,
" . . . + + + @ @ @ @ + + + @ @ @ @ @ @ + + + + @ @ @ @ + . . . . " ,
" . . + + + @ @ @ @ + + + @ @ @ @ @ @ @ @ + + + @ @ @ @ @ + + . . " ,
" . + + @ @ @ @ @ @ + + + @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ + + " ,
" . + # + @ @ @ @ @ @ + + @ @ @ @ + + + @ @ @ @ @ @ @ @ @ @ @ @ + " ,
" . + # # + + @ @ @ @ + + + @ @ @ + + + + + @ @ @ @ @ @ @ @ $ @ . " ,
" . + # # # + + @ @ @ @ + + + @ @ @ + + + @ @ @ @ @ + + $ $ $ @ . " ,
" . + # # # # + + + @ @ @ + + + + + + + @ @ @ @ @ + @ $ $ $ $ @ . " ,
" . + # # # # # + + + @ @ @ @ + + + @ @ @ @ + + @ $ $ $ $ $ $ + . " ,
" . + # # # # # # + + + + @ @ @ @ @ @ @ + + @ $ $ $ $ $ $ $ $ + . " ,
" . + # # # # # # # + # # + @ @ @ @ + + + $ $ $ $ $ $ @ @ $ $ + . " ,
" . + # # # + + + # # + # # + @ @ + + @ $ $ $ $ $ $ + + $ $ $ + . " ,
" . + # # # + + + + # # + # # + @ @ $ $ $ $ $ $ $ @ + @ $ $ @ + . " ,
" . + # # # + + + + + + # + + + @ $ $ @ + @ $ $ @ + + $ $ $ @ + . " ,
" . + # # # # + + + + + + + # + + $ $ @ + @ $ $ + + $ $ $ $ + . . " ,
" . + + # # # # + + + + + + # + + $ $ @ + @ $ + + @ $ $ $ $ + . . " ,
" . + # # # # # + + + + + # # + + $ $ + + @ + + + $ $ $ $ $ + . . " ,
" . + + # # # # + + + # # + # + + $ $ + + + + + @ $ $ $ $ $ + . . " ,
" . + + # # # # + + + # # # # + + $ $ + + + + + + @ $ $ $ @ + . . " ,
" . + # # # # # + + # # # # # + + $ $ + + + @ + + + + @ $ @ + . . " ,
" . + # # # # # + + # # # # # + + $ $ + + @ $ $ @ + + + $ @ @ . . " ,
" . + + # # # # + + # # # # # + + $ $ + + $ $ $ $ $ + @ $ @ + + . " ,
" . + + # # # # + + # # # # # + + $ $ + + $ $ $ $ $ $ $ $ + + + . " ,
" . + + + # # # # + # # # # # + + $ $ + + $ $ $ $ $ $ $ @ + + + . " ,
" . . + + + # # # # # # # # # + @ $ $ + @ $ $ $ $ $ $ + + + . . . " ,
" . . . + + + # # # # # # # # + @ $ $ $ $ $ $ $ $ @ + + + . . . . " ,
" . . . . . + + + # # # # # # + @ $ $ $ $ $ $ $ + + + . . . . . . " ,
" . . . . . . + + + # # # # # + @ $ $ $ $ $ @ + + . . . . . . . . " ,
" . . . . . . . + + + # # # # + @ $ $ $ $ + + + . . . . . . . . . " ,
" . . . . . . . . . + + # # # + $ $ $ @ + + . . . . . . . . . . . " ,
" . . . . . . . . . . + + # # + $ @ + + + . . . . . . . . . . . . " ,
" . . . . . . . . . . . + + + + + + + . . . . . . . . . . . . . . " ,
" . . . . . . . . . . . . . + + + + . . . . . . . . . . . . . . . " 
} ;

GtkWidget *close_button;
GtkWidget *tooltips_button;
GtkWidget *text_button,*icon_button,*both_button;
GtkWidget *entry;

void radio_event(GtkWidget *widget,gpointer data){
	if(GTK_TOGGLE_BUTTON(text_button)->active)
		gtk_toolbar_set_style(GTK_TOOLBAR(data),GTK_TOOLBAR_TEXT);
	else if(GTK_TOGGLE_BUTTON(icon_button)->active)
		gtk_toolbar_set_style(GTK_TOOLBAR(data),GTK_TOOLBAR_ICONS);
	else if(GTK_TOGGLE_BUTTON(both_button)->active)
		gtk_toolbar_set_style(GTK_TOOLBAR(data),GTK_TOOLBAR_BOTH);
}

void toggle_event(GtkWidget *self,gpointer data){
	printf("%s:active is %d\n",__func__,GTK_TOGGLE_BUTTON(self)->active);
	gtk_toolbar_set_tooltips(GTK_TOOLBAR(data),GTK_TOGGLE_BUTTON(self)->active);
}

int main(int argc,char **argv){
	GtkWidget *dialog,*handlebox,*toolbar,*iconw;
	GdkPixmap *icon;
	GdkBitmap *mask;

	gtk_init(&argc,&argv);
	dialog = gtk_dialog_new();
	gtk_window_set_title(GTK_WINDOW(dialog),"GTKToolBar Tutorial");
	gtk_widget_set_usize(GTK_WIDGET(dialog),600,300);
	GTK_WINDOW(dialog)->allow_shrink = TRUE;

	gtk_signal_connect(GTK_OBJECT(dialog),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
	gtk_widget_realize(dialog);

	handlebox = gtk_handle_box_new();
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),handlebox,FALSE,FALSE,5);

	//toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,GTK_TOOLBAR_BOTH);
	toolbar = gtk_toolbar_new();
	gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar),GTK_ORIENTATION_HORIZONTAL);
	gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),GTK_TOOLBAR_BOTH);

	gtk_container_set_border_width(GTK_CONTAINER(toolbar),5);
	//gtk_toolbar_set_space_size(GTK_TOOLBAR(toolbar),5);
	gtk_container_add(GTK_CONTAINER(handlebox),toolbar);

	icon = gdk_pixmap_create_from_xpm_d(dialog->window,&mask,&dialog->style->white,gtk_xpm);
	iconw = gtk_pixmap_new(icon,mask);
	close_button = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
		"Close","Close this app","Private",iconw,G_CALLBACK(gtk_main_quit),NULL);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	iconw = gtk_pixmap_new(icon,mask);
	icon_button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
		GTK_TOOLBAR_CHILD_RADIOBUTTON,NULL,"Icon",
		"Only icons in toolbar","Private",iconw,G_CALLBACK(radio_event),toolbar);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	iconw = gtk_pixmap_new(icon,mask);
	text_button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
		GTK_TOOLBAR_CHILD_RADIOBUTTON,icon_button,"Text","Only texts in toolbar",
		"Private",iconw,G_CALLBACK(radio_event),toolbar);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	iconw = gtk_pixmap_new(icon,mask);
	both_button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
			GTK_TOOLBAR_CHILD_RADIOBUTTON,text_button,"Both",
			"Icons and text in toolbar","Private",iconw,G_CALLBACK(radio_event),toolbar);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(both_button),TRUE);
	iconw = gtk_pixmap_new(icon,mask);
	tooltips_button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
		GTK_TOOLBAR_CHILD_TOGGLEBUTTON,NULL,"Tooltips",
		"Toolbar with or without tips","Private",iconw,G_CALLBACK(toggle_event),toolbar);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tooltips_button),TRUE);

	entry = gtk_entry_new();
	gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),entry,"This is just an entry","Private");
	gtk_widget_show(entry);

	gtk_widget_show(toolbar);
	gtk_widget_show(handlebox);
	gtk_widget_show(dialog);

	gtk_main();
	return 0;
}